package com.zhl.study.getThreadResult;

import lombok.extern.slf4j.Slf4j;

/**
 * @description join()方法
 * 通过调用线程的join()方法,可以等待该线程执行完毕并获取它的返回结果。
 * @Author: z156940l@outlook.com
 * @className JoinWay
 * @Date: 2024/5/23 10:35
 */
@Slf4j
public class JoinWay {
    public static void testJoin() {
        Thread t = new Thread(new ResultThread());
        t.start();

        try {
            t.join(); // 主线程等待ResultThread线程执行完毕
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        log.info("Thread execution result: {}", ResultThread.getResult());
    }
}
